-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JP-3653: Nsclean speedup #8547
JP-3653: Nsclean speedup #8547
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8547 +/- ##
==========================================
+ Coverage 58.02% 58.52% +0.50%
==========================================
Files 388 388
Lines 38977 38958 -19
==========================================
+ Hits 22617 22802 +185
+ Misses 16360 16156 -204 ☔ View full report in Codecov by Sentry. |
@t-brandt Looks good to me; can you please add a change log entry? |
Ok, I updated CHANGES.rst. |
Thanks- minor comment that the number of dashes underneath the title 'nsclean' should be the same number of characters as the step name. I'm not honestly sure why, but @hbushouse has frequently had to remind me about it. |
The number of underline characters needs to be at least as long as the title above it, but can be longer (without doing harm). It just can't be shorter or the sphinx parser will barf. |
Ok, I adjusted the number of dashes. |
I tried to run regtests for this PR:
|
It looks like these changes are only in the NSClean class. Is it possible to make similar changes in the NSCleanSubarray class too? I'm wondering if this would enable support for the ALLSLITS subarray - right now, it uses so much memory that it crashes the kernel if attempted, so support for this subarray is explicitly turned off. |
@melanieclarke The NSCleanSubarray already does something close to the changes I made. Unfortunately, I think that the reason it fails is Line 471 in 41f24b7
This results in a matrix of size npix x npix (see Line 465 in 41f24b7
If a subarray is 1000x100 pixels, for example, then Line 471 referenced above produces a matrix with 1e10 elements, which may not fit in RAM. This problem does not affect the full array version of NSClean because that operates row-by-row, so that there are never more than 2048 pixels to be fit simultaneously, meaning that the equivalent matrix is at most 2048^2: Line 163 in 41f24b7
This array size/memory issue in NSCleanSubarray can be fixed, but not quite so simply as with the pull request here. If it is a priority for the mission I can spend a bit more time to propose a fix. |
Maybe I'm missing something, but can we simply swap subarray mode to run row-by-row as well? |
@drlaw1558 Yes, we can do that. The best thing is probably to do something intermediate: to process as many rows simultaneously as we think we can profitably fit the Fourier modes. Assuming I am interpreting Bernie's code right, line Line 336 in 41f24b7
defines the cutoff and cuton frequencies as ~50 kHz and ~1 kHz, which would correspond to 2 pixels and 100 pixels. So that would imply that doing a few rows at a time would be best, I think, with the number depending on subarray size. I don't think this would be a ton of work to implement, but I think it would be good to consult with Bernie to confirm my intuition. We might then compute backgrounds over overlapping regions and then use weighted averages to construct a smooth combined background. |
@t-brandt Sounds like that's sufficiently different that it makes sense to consider separately rather than tying it to the work currently here. I'll file a separate ticket to track it; https://jira.stsci.edu/browse/JP-3654 |
Another regtest run started at https://plwishmaster.stsci.edu:8081/job/RT/job/JWST-Developers-Pull-Requests/1524 |
Regtest run https://plwishmaster.stsci.edu:8081/job/RT/job/JWST-Developers-Pull-Requests/1525/ had no failures or differences, so this looks good. |
Resolves JP-3653
Closes #8548
This PR improves the run time of the NSClean algorithm (not counting the time to construct a pixel mask in NIRSpec) by a factor between 10 and 20. This is achieved by representing a diagonal weight matrix as a vector and using vector multiplication and broadcasting to achieve equivalent results without extra multiplications by zero and additions of zero. The changes are entirely within NSClean.fit(). Nothing outside of this routine appears any different, and I have verified that the results of the calculation are the same.
Checklist for PR authors (skip items if you don't have permissions or they are not applicable)
CHANGES.rst
within the relevant release sectionHow to run regression tests on a PR